import 'package:FineArt/core/http/base_dio.dart';
import 'package:json_annotation/json_annotation.dart';
import 'package:retrofit/retrofit.dart';
import 'package:dio/dio.dart';
import '../../constants.dart';

part 'home_api.g.dart';

@RestApi(baseUrl: kBaseUrl)
abstract class HomeApi {
  factory HomeApi({Dio dio, String baseUrl}) {
    dio ??= BaseDio.getInstance().getDio();
    return _HomeApi(dio, baseUrl: baseUrl);
  }

  @GET("/api/v1/home/banner") //轮播banner
  Future<BannersResponse> banners();

  @GET("/api/v1/home/works") //推荐优秀作品信息
  Future<WorksResponse> works(@Query("pg") int page, @Query("size") int size);

  @GET("/api/v1/home/techart") //课堂范画
  Future<TechartResponse> techarts(
      @Query("pg") int page, @Query("size") int size);

  @GET("/api/v1/home/tutor") //推荐教师
  Future<TutorResponse> teachers(
      @Query("pg") int page, @Query("size") int size);
}

//---banners----
@JsonSerializable()
class BannersResponse {
  String requestId;
  int code;
  String msg;
  List<HomeBanner> data;

  BannersResponse({this.requestId, this.code, this.msg, this.data});

  factory BannersResponse.fromJson(Map<String, dynamic> json) =>
      _$BannersResponseFromJson(json);
}

@JsonSerializable()
class HomeBanner {
  int id;
  String label;
  String url; //  轮播图url
  String linkurl; //  轮播图对应的链接地址，如果为空，则没有超链地址

  HomeBanner({this.id, this.label, this.url, this.linkurl});

  factory HomeBanner.fromJson(Map<String, dynamic> json) =>
      _$HomeBannerFromJson(json);
}
//---end banners----

//--------recommended works-----
@JsonSerializable()
class WorksResponse {
  String requestId;
  int code;
  String msg;
  WorksList data;

  WorksResponse({this.requestId, this.code, this.msg, this.data});

  factory WorksResponse.fromJson(Map<String, dynamic> json) =>
      _$WorksResponseFromJson(json);
}

@JsonSerializable()
class WorksList {
  int count;
  int pageIndex;
  int pageSize;
  List<WorksGroup> list;

  WorksList({this.count, this.pageIndex, this.pageSize, this.list});

  factory WorksList.fromJson(Map<String, dynamic> json) =>
      _$WorksListFromJson(json);
}

@JsonSerializable()
class WorksGroup {
  String date;
  List<Works> items;

  WorksGroup({this.date, this.items});

  factory WorksGroup.fromJson(Map<String, dynamic> json) =>
      _$WorksGroupFromJson(json);
}

@JsonSerializable()
class Works {
  int id;
  String uid;
  String title;
  String url;
  String thumburl;
  String sdurl;
  String hdurl;
  int type;
  String ext;
  String nickname;
  String portrait;
  int resid;

  Works(
      {this.id,
      this.uid,
      this.title,
      this.url,
      this.thumburl,
      this.sdurl,
      this.hdurl,
      this.type,
      this.ext,
      this.nickname,
      this.portrait,
      this.resid});

  factory Works.fromJson(Map<String, dynamic> json) => _$WorksFromJson(json);
}
//--------end recommended works-----

//--------recommended techart-----范画
@JsonSerializable()
class TechartResponse {
  String requestId;
  int code;
  String msg;

  TechartList data;

  TechartResponse({this.requestId, this.code, this.msg, this.data});

  factory TechartResponse.fromJson(Map<String, dynamic> json) =>
      _$TechartResponseFromJson(json);
}

@JsonSerializable()
class TechartList {
  int count;
  int pageIndex;
  int pageSize;
  List<TechartGroup> list;

  TechartList({this.count, this.pageIndex, this.pageSize, this.list});

  factory TechartList.fromJson(Map<String, dynamic> json) =>
      _$TechartListFromJson(json);
}

@JsonSerializable()
class TechartGroup {
  String date;
  List<Techart> items;

  TechartGroup({this.date, this.items});

  factory TechartGroup.fromJson(Map<String, dynamic> json) =>
      _$TechartGroupFromJson(json);
}

@JsonSerializable()
class Techart {
  int id;
  String uid;
  String title;
  String url;
  String thumburl;
  String sdurl;
  String hdurl;
  int type;
  String ext;
  String nickname;
  String portrait;
  int resid;

  Techart(
      {this.id,
      this.uid,
      this.title,
      this.url,
      this.thumburl,
      this.sdurl,
      this.hdurl,
      this.type,
      this.ext,
      this.nickname,
      this.portrait,
      this.resid});

  factory Techart.fromJson(Map<String, dynamic> json) =>
      _$TechartFromJson(json);
}
//--------end recommended techart-----范画

//-----recommended teacher----老师
@JsonSerializable()
class TutorResponse {
  String requestId;
  int code;
  String msg;

  TutorList data;

  TutorResponse({this.requestId, this.code, this.msg, this.data});

  factory TutorResponse.fromJson(Map<String, dynamic> json) =>
      _$TutorResponseFromJson(json);
}

@JsonSerializable()
class TutorList {
  int count;
  int pageIndex;
  int pageSize;
  List<Tutor> list;

  TutorList({this.count, this.pageIndex, this.pageSize, this.list});

  factory TutorList.fromJson(Map<String, dynamic> json) =>
      _$TutorListFromJson(json);
}

@JsonSerializable()
class Tutor {
  int id;
  String nickname;
  String url;
  String reflink;

  Tutor({this.id, this.nickname, this.url, this.reflink});

  factory Tutor.fromJson(Map<String, dynamic> json) => _$TutorFromJson(json);
}
//---end recommended teacher----老师
